package com.yupi.springbootinit.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.exception.ThrowUtils;
import com.yupi.springbootinit.model.entity.InterfaceInfo;
import com.yupi.springbootinit.service.InterfaceInfoService;
import com.yupi.springbootinit.mapper.InterfaceInfoMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author moresuo
* @description 针对表【interface_info(接口信息表)】的数据库操作Service实现
* @createDate 2024-03-12 01:58:24
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
    implements InterfaceInfoService{

    @Override
    public void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add) {
        //判断接口对象是否为空
        ThrowUtils.throwIf(interfaceInfo==null, ErrorCode.PARAMS_ERROR);
        //获取接口对象名称
        String name=interfaceInfo.getName();
        if(add){
            ThrowUtils.throwIf(StringUtils.isAnyBlank(name),ErrorCode.PARAMS_ERROR);
        }
        if(StringUtils.isNotBlank(name)&&name.length()>50){
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "名字过长");
        }
    }
}




